﻿
namespace Spotted.Core.ExtensionMethods
{
    public static class StringExtensions
    {
        /// <summary>
        /// Attempt to parse a String to a Double type. Return a defaultValue if the parse fails
        /// </summary>
        /// <param name="str">The string instance being extended which will be parsed</param>
        /// <param name="defaultValue">The default value to return in the event of a parse fail</param>
        /// <returns>An instance of double</returns>
        public static double AsDouble(this string str, double defaultValue = double.MinValue)
        {
            double doubleVal;
            if (!double.TryParse(str, out doubleVal))
            {
                return defaultValue;
            }

            return doubleVal;
        }
    }
}
